var inps = document.querySelectorAll("input");

inps[1].onfocus = function () {
    this.style.color = "";
    sp.innerHTML = "";
    this.style.borderColor = "#20c997";
}
inps[1].onblur = function () {
    if (this.value == "") {
        sp.innerHTML = "用户名不能为空!";
        sp.style.color = "red";
        this.style.borderColor = "red";
        return;
    }
    sp.style.color = "green";
    this.style.borderColor = "";
}

inps[2].onfocus = function () {
    this.style.color = "";
    sp2.innerHTML = "";
    this.style.borderColor = "#20c997";
}
inps[2].onblur = function () {
    if (this.value == "") {
        sp2.innerHTML = "密码不能为空!";
        sp2.style.color = "red";
        this.style.borderColor = "red";
        return;
    }
    sp2.style.color = "green";
    this.style.borderColor = "";
}

form.onsubmit = e => {
    inps[1].onblur();
    inps[2].onblur();
    var spans=document.querySelectorAll("#form span");
    for (var i = 1; i < spans.length; i++) {
        if (spans[i].style.color != "green") {
            return false;
        }
    }
}